
#ifndef __VOL_WTL_UI_SCINTILLA_H__
#define __VOL_WTL_UI_SCINTILLA_H__

#include "Scintilla.h"
#include "ILoader.h"
#include "SciLexer.h"

class IScintillaEventListener : public IBaseEventListener
{
public:
    virtual void OnSavePointChange () = 0;
    virtual void OnSavePointLeft () = 0;
    virtual void OnModifyAttemptRo () = 0;
	virtual void OnMarginLeftClick (int modifiers, Sci_Position position, int margin) = 0;
	virtual void OnMarginRightClick (int modifiers, Sci_Position position, int margin) = 0;
	virtual void OnAutocSelection (Sci_Position position, const char *text, int ch, int listCompletionMethod) = 0;
	virtual void OnUserListSelection (int listType, Sci_Position position, const char *text, int ch, int listCompletionMethod) = 0;
	virtual void OnMacroRecord (int message, uptr_t wParam, sptr_t lParam) = 0;
//	virtual void OnCharAdded (int characterSource, int ch) = 0;
	virtual void OnCharAdded (int ch) = 0;
	virtual void OnDoubleClick (Sci_Position position, Sci_Position line, int modifiers) = 0;
	virtual void OnUpdateUI (int updated) = 0;
    virtual void OnPainted () = 0;
    virtual void OnDwellStart (Sci_Position position, int x, int y) = 0;
    virtual void OnDwellEnd (Sci_Position position, int x, int y) = 0;
    virtual void OnZoom () = 0;
    virtual void OnHotspotClick (Sci_Position position, int modifiers) = 0;
    virtual void OnHotspotDoubleClick (Sci_Position position, int modifiers) = 0;
    virtual void OnHotspotReleaseClick (Sci_Position position, int modifiers) = 0;
    virtual void OnIndicatorClick (Sci_Position position, int modifiers) = 0;
    virtual void OnIndicatorRelease (Sci_Position position, int modifiers) = 0;
    virtual void OnCallTipClick (Sci_Position position) = 0;
    virtual void OnAutoCCancelled () = 0;
    virtual void OnAutoCCharDeleted () = 0;
	virtual void OnAutoCCompleted (Sci_Position position, const char *text, int ch, int listCompletionMethod) = 0;
	virtual void OnAutoCSelectionChange (int listType, const char* text, Sci_Position position) = 0;
	//MOD
	virtual void OnChangeLineState (Sci_Position line, int eventSoure, bool multiStep, bool lastStep, bool startAction) = 0;
    virtual void OnInsertText (Sci_Position position, Sci_Position length, const char* text, Sci_Position linesAdded, int eventSoure, bool multiStep, bool lastStep, bool startAction) = 0;
    virtual void OnDeleteText (Sci_Position position, Sci_Position length, const char* text, Sci_Position linesAdded, int eventSoure, bool multiStep, bool lastStep, bool startAction) = 0;
    virtual void OnChangeStyle (Sci_Position position, Sci_Position length, int eventSoure, bool multiStep, bool lastStep, bool startAction) = 0;
    virtual void OnChangeFold (Sci_Position line, int foldLevelNow, int foldLevelPrev, int eventSoure, bool multiStep, bool lastStep, bool startAction) = 0;
    virtual void OnChangeMarker (Sci_Position line, int eventSoure, bool multiStep, bool lastStep, bool startAction) = 0;
    virtual void OnInsertCheck (Sci_Position position, Sci_Position length, const char* text, int eventSoure, bool multiStep, bool lastStep, bool startAction) = 0;
	virtual void OnChangeMargin (Sci_Position line, int eventSoure, bool multiStep, bool lastStep, bool startAction) = 0;
	virtual void OnChangeAnnotation (Sci_Position line, int eventSoure, bool multiStep, bool lastStep, bool startAction) = 0;
	virtual void OnChangeEolAnnotation (Sci_Position line, int eventSoure, bool multiStep, bool lastStep, bool startAction) = 0;
	virtual void OnChangeTabStops (Sci_Position line, int eventSoure, bool multiStep, bool lastStep, bool startAction) = 0;
    virtual void OnBeforeInsert (Sci_Position position, Sci_Position length, const char* text, int eventSoure, bool multiStep, bool lastStep, bool startAction) = 0;
    virtual void OnBeforeDelete (Sci_Position position, Sci_Position length, int eventSoure, bool multiStep, bool lastStep, bool startAction) = 0;
    virtual void OnChangeIndicator (Sci_Position position, Sci_Position length, int eventSoure, bool multiStep, bool lastStep, bool startAction) = 0;
    virtual void OnLexerState (Sci_Position position, Sci_Position length, int eventSoure, bool multiStep, bool lastStep, bool startAction) = 0;
    virtual void OnContainer (int token, int eventSoure, bool multiStep, bool lastStep, bool startAction) = 0;
};

class CVWnd_Scintilla : public CWindowImpl<CVWnd_Scintilla>
{
    BEGIN_DECLARE_VOL_NATIVE_WND_CLASS (CVWnd_Scintilla, IScintillaEventListener, FALSE)
        REFLECTED_NOTIFY_CODE_HANDLER_EX  (SCN_SAVEPOINTREACHED, OnSavePointChange)
        REFLECTED_NOTIFY_CODE_HANDLER_EX  (SCN_SAVEPOINTLEFT, OnSavePointLeft)
        REFLECTED_NOTIFY_CODE_HANDLER_EX  (SCN_MODIFYATTEMPTRO, OnModifyAttemptRo)
        REFLECTED_NOTIFY_CODE_HANDLER_EX  (SCN_MODIFIED, OnModified)
        REFLECTED_NOTIFY_CODE_HANDLER_EX  (SCN_MARGINCLICK, OnMarginLeftClick)
        REFLECTED_NOTIFY_CODE_HANDLER_EX  (SCN_MARGINRIGHTCLICK, OnMarginRightClick)
        REFLECTED_NOTIFY_CODE_HANDLER_EX  (SCN_AUTOCSELECTION, OnAutocSelection)
        REFLECTED_NOTIFY_CODE_HANDLER_EX  (SCN_USERLISTSELECTION, OnUserListSelection)
        REFLECTED_NOTIFY_CODE_HANDLER_EX  (SCN_MACRORECORD, OnMacroRecord)
        REFLECTED_NOTIFY_CODE_HANDLER_EX  (SCN_CHARADDED, OnCharAdded)
        REFLECTED_NOTIFY_CODE_HANDLER_EX  (SCN_DOUBLECLICK, OnDoubleClick)
        REFLECTED_NOTIFY_CODE_HANDLER_EX  (SCN_UPDATEUI, OnUpdateUI)
        REFLECTED_NOTIFY_CODE_HANDLER_EX  (SCN_PAINTED, OnPainted)
        REFLECTED_NOTIFY_CODE_HANDLER_EX  (SCN_DWELLSTART, OnDwellStart)
        REFLECTED_NOTIFY_CODE_HANDLER_EX  (SCN_DWELLEND, OnDwellEnd)
        REFLECTED_NOTIFY_CODE_HANDLER_EX  (SCN_ZOOM, OnZoom)
        REFLECTED_NOTIFY_CODE_HANDLER_EX  (SCN_HOTSPOTCLICK, OnHotspotClick)
        REFLECTED_NOTIFY_CODE_HANDLER_EX  (SCN_HOTSPOTDOUBLECLICK, OnHotspotDoubleClick)
        REFLECTED_NOTIFY_CODE_HANDLER_EX  (SCN_HOTSPOTRELEASECLICK, OnHotspotReleaseClick)
        REFLECTED_NOTIFY_CODE_HANDLER_EX  (SCN_INDICATORCLICK, OnIndicatorClick)
        REFLECTED_NOTIFY_CODE_HANDLER_EX  (SCN_INDICATORRELEASE, OnIndicatorRelease)
        REFLECTED_NOTIFY_CODE_HANDLER_EX  (SCN_CALLTIPCLICK, OnCallTipClick)
        REFLECTED_NOTIFY_CODE_HANDLER_EX  (SCN_AUTOCCANCELLED, OnAutoCCancelled)
        REFLECTED_NOTIFY_CODE_HANDLER_EX  (SCN_AUTOCCHARDELETED, OnAutoCCharDeleted)
        REFLECTED_NOTIFY_CODE_HANDLER_EX  (SCN_AUTOCCOMPLETED, OnAutoCCompleted)
        REFLECTED_NOTIFY_CODE_HANDLER_EX  (SCN_AUTOCSELECTIONCHANGE, OnAutoCSelectionChange)
    END_DECLARE_VOL_NATIVE_WND_CLASS_MAYBE_CONTAINER ()
    DECLARE_WND_SUPERCLASS (NULL, _T ("Scintilla"))

private:
	SciFnDirect m_fnDirect;
	sptr_t m_ptrDirect;
	
    LRESULT OnSavePointChange (NMHDR* pNMHDR);
    LRESULT OnSavePointLeft (NMHDR* pNMHDR);
	LRESULT OnModifyAttemptRo (NMHDR* pNMHDR);
	LRESULT OnModified (NMHDR* pNMHDR);
	LRESULT OnMarginLeftClick (NMHDR* pNMHDR);
	LRESULT OnMarginRightClick (NMHDR* pNMHDR);
	LRESULT OnAutocSelection (NMHDR* pNMHDR);
	LRESULT OnUserListSelection (NMHDR* pNMHDR);
	LRESULT OnMacroRecord (NMHDR* pNMHDR);
	LRESULT OnCharAdded (NMHDR* pNMHDR);
	LRESULT OnDoubleClick (NMHDR* pNMHDR);
	LRESULT OnUpdateUI (NMHDR* pNMHDR);
	LRESULT OnPainted (NMHDR* pNMHDR);
	LRESULT OnDwellStart (NMHDR* pNMHDR);
	LRESULT OnDwellEnd (NMHDR* pNMHDR);
	LRESULT OnZoom (NMHDR* pNMHDR);
	LRESULT OnHotspotClick (NMHDR* pNMHDR);
	LRESULT OnHotspotDoubleClick (NMHDR* pNMHDR);
	LRESULT OnHotspotReleaseClick (NMHDR* pNMHDR);
	LRESULT OnIndicatorClick (NMHDR* pNMHDR);
	LRESULT OnIndicatorRelease (NMHDR* pNMHDR);
	LRESULT OnCallTipClick (NMHDR* pNMHDR);
	LRESULT OnAutoCCancelled (NMHDR* pNMHDR);
	LRESULT OnAutoCCharDeleted (NMHDR* pNMHDR);
	LRESULT OnAutoCCompleted (NMHDR* pNMHDR);
	LRESULT OnAutoCSelectionChange (NMHDR* pNMHDR);

public:
    CVWnd_Scintilla ();
	BOOL CreateScintilla (CVolNativeWndCreateParam* pCreateParam);
	sptr_t SendEditor (unsigned int iMessage, uptr_t wParam = 0, sptr_t lParam = 0);

	static void RegisterScintilla();
	static void ReleaseScintilla();
};

#endif